package main

import "fmt"

type Student struct {
	Name  string
	Age   int8
	Score int8
}

type CollegeStudent struct {
	//CollegeStudent继承于Student
	Student
	Address string
	Name    string
}

type PrimarySchoolStudent struct {
	Student
	Parent string
}

func (s *Student) sayOk() {
	fmt.Println("student sayok", s.Name)
}

func (s *Student) sayByBy() {
	fmt.Println("student saybyby", s.Name)
}

func (s *CollegeStudent) sayOk() {
	fmt.Println("collegeStudent sayOK", s.Name)
}

//继承的基本语法
func main() {
	var coll CollegeStudent
	coll.Address = "henan"
	//如果子结构体重写父结构体的属性，
	//并且在赋值时没有指定父结构体名，则会赋值给子结构体属性
	coll.Name = "tom"
	//coll.Student.Name = "jetty"
	coll.Student.Age = 12
	coll.Score = 34
	fmt.Println(coll)

	//使用细节
	//相当于Java中的重写，如果此子结构体重写了父结构体的方法，则以子结构体为准
	//如果想要调用结构体则，需要具体指定父结构体
	coll.sayByBy()
	coll.Student.sayOk()
	var stu Student = Student{
		Name:  "jack",
		Age:   23,
		Score: 23,
	}
	stu.sayOk()
}
